package com.yanqu.road.server.cmd.activity.winterLove;

import com.yanqu.road.entity.activity.winterLove.WinterLoveUserData;
import com.yanqu.road.pb.activity.WinterLoveProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.winterLove.WinterLoveModule;
import com.yanqu.road.server.manger.activity.winterLove.WinterLoveMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_WINTER_LOVE_KICK_ANIMAL,desc = "冬季恋歌踢出动物")
public class WinterLoveKickAnimalCmd extends AbstractCommand {

    int animalNum ;
    int level;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WinterLoveProto.KickAnimalReqMsg reqMsg = WinterLoveProto.KickAnimalReqMsg.parseFrom(packet.getBytes());
        animalNum=reqMsg.getAnimalNum();
        level=reqMsg.getLevel();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (WinterLoveMgr.getShowTimeActivityId()==0){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if (!WinterLoveMgr.activityInTime()){
            ret= GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        WinterLoveModule module=player.getModule(WinterLoveModule.class);
        WinterLoveUserData userData = module.getUserData();
        if (userData==null){
            ret = GameErrorCode.E_WINTER_LOVE_ACTIVITY_NO_UNLOCK;
            return;
        }
        if (level!=1&&level!=2){
            ret = GameErrorCode.E_WINTER_LOVE_LEVEL_ERROR;
            return;
        }
        ret = player.getModule(WinterLoveModule.class).kickAnimal(animalNum,level);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret!=0){
            WinterLoveProto.KickAnimalRespMsg.Builder respMsg=WinterLoveProto.KickAnimalRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_WINTER_LOVE_KICK_ANIMAL_RESULT,respMsg);
        }
    }
}
